﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SHW_UP.BP;

namespace SHW_UP.UI
{
    public partial class frmPasswd : Form
    {
        public frmPasswd()
        {
            InitializeComponent();
        }

        private void passwdModify_Click(object sender, EventArgs e)
        {
            string passwd = string.Empty;
            if (InfoUtils.parTable.Contains("passwd"))
            {
                passwd = (string)InfoUtils.parTable["passwd"];
            }
            else
            {
                passwd = "000000";
            }
            string str = "YGYHMM," + passwd + "," + this.usernameText.Text + ",";
            if (InfoUtils.sendInfoTable.ContainsKey("YGYHMM"))
            {
                InfoUtils.sendInfoTable.Remove("YGYHMM");
            }
                InfoUtils.sendInfoTable.Add("YGYHMM", str);
            this.passwdGridView.Rows[0].Cells[0].Value = this.usernameText.Text;
            this.passwdGridView.Rows[0].Cells[1].Value = this.passwdText.Text;
            //SerialPortSender.sendStrInfo(str, this.serialPort);
        }
        private DataTable dt = new DataTable();
        private void frmPasswd_Load(object sender, EventArgs e)
        {
            string passwd = string.Empty;
            if (InfoUtils.parTable.Contains("passwd"))
            {
                passwd = (string)InfoUtils.parTable["passwd"];
            }
            else
            {
                InfoUtils.parTable.Add("passwd","000000");
                passwd = "000000";
            }
            this.passwdGridView.Columns.Clear();
            this.passwdGridView.ReadOnly = true;
            dt.Columns.Add("用户密码");
            dt.Columns.Add("终端密码");
            DataRow dr1 = dt.NewRow();
            dr1[0] = passwd;
            dr1[1] = "123456";
            dt.Rows.Add(dr1);
            this.passwdGridView.DataSource = dt;
        }

        private void passwdGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        private void GridView_RowClick(object sender, EventArgs e)
        {
            if (this.passwdGridView.SelectedRows.Count > 0)
            {
                this.usernameText.Text = this.passwdGridView.SelectedRows[0].Cells[0].Value.ToString();
                this.passwdText.Text = "123456";
            }
        }

        private void passwdRefresh_Click(object sender, EventArgs e)
        {
            string passwd = string.Empty;
            if (InfoUtils.parTable.Contains("passwd"))
            {
                passwd = (string)InfoUtils.parTable["passwd"];
            }
            else
            {
                InfoUtils.parTable.Add("passwd", "000000");
                passwd = "000000";
            }
            this.passwdGridView.Rows[0].Cells[0].Value = passwd;
                this.passwdGridView.Rows[0].Cells[1].Value = "123456";
                this.passwdGridView.ClearSelection();
        }
    }
}
